include ./make.settings

.PHONY: libsfiot libplatform sample all clean 

ifeq ($(prefix), )
 prefix=.
$(info prefix is: $(prefix))
endif


all: libsdk libplatform  sample
	$(info make all)

libsdk:
	mkdir -p ./build_out 
	$(info make sfiot library)
	make -C ./src/ \
    	-e \
    	CC=$(PLATFORM_CC) \
    	AR=$(PLATFORM_AR) \
    	OS=$(PLATFORM_OS) \
    	NETWORK=$(PLATFORM_NETWORK) \
    	SDK_LIB_NAME=$(SFIOT_SDK_LIB_NAME) \
    	BUILD_TYPE=$(BUILD_TYPE)
	
libplatform:
	mkdir -p ./build_out
	$(info make platform library)
	make -C ./src/platform/ \
		-e \
		CC=$(PLATFORM_CC) \
		AR=$(PLATFORM_AR) \
		OS=$(PLATFORM_OS) \
		NETWORK=$(PLATFORM_NETWORK) \
		PLATFORM_LIB_NAME=$(SFIOT_PLATFORM_LIB_NAME) \
		BUILD_TYPE=$(BUILD_TYPE)
	
sample:
	$(info make mqtt samples)
	make -C ./samples/mqtt/
	$(info make device shadow samples)
	make -C ./samples/deviceshadow/


install:
	mkdir -p $(prefix)/lib
	mkdir -p $(prefix)/include
	find ./src/utility -name '*.h' -exec cp -vf {} $(prefix)/include/ \;
	find ./src/list -name '*.h' -exec cp -vf {} $(prefix)/include/ \;
	find ./src/xxtea -name '*.h' -exec cp -vf {} $(prefix)/include/ \;
	find ./src/md5 -name '*.h' -exec cp -vf {} $(prefix)/include/ \;
	find ./src/platform -maxdepth 1  -name '*.h' -exec cp -vf {} $(prefix)/include/ \;
	find ./src/network -maxdepth 1  -name '*.h' -exec cp -vf {} $(prefix)/include/ \;
	cp -vf ./src/mqttclient/network.h  $(prefix)/include/
	cp -vf ./src/mqttclient/SefonIotMqttClient.h  $(prefix)/include/
	cp -vf ./src/shadow/SefonIotShadow.h $(prefix)/include/
	cp -rvf ./build_out/ $(prefix)/lib
	find ./build_out -name '*.a' -exec cp -vf {} $(prefix)/lib/ \;

clean:
	-rm -fr ./build_out/
	$(info make clean aliot library)	
	make -C ./src/ clean 
	$(info make clean platform library)	
	make -C ./src/platform clean
	$(info make clean mqtt sample)
	make -C ./samples/mqtt clean
	$(info make clean device shadow sample)
	make -C ./samples/deviceshadow clean
